package com.dci.controller.project;

import com.dci.model.project.ProjectSchedule;
import com.dci.param.SearchMap;
import com.dci.result.JsonData;
import com.dci.result.PageResult;
import com.dci.service.project.ProjectExamineService;
import com.dci.service.project.ProjectInfoService;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * All rights Reserved, Designed By 姑苏区政府大数据中心
 *
 * @version V1.0
 * @Title: null.java
 * @Package com.dci.controller.project
 * @Description: 储备库管理
 * @author: 张星亮
 * @date: 2019/2/25
 * @Copyright: 2019 姑苏区政府大数据中心. All rights reserved.
 * 注意：本内容仅限于姑苏区政府大数据中心内部传阅，禁止外泄以及用于其他的商业目
 */
@Controller
@RequestMapping("/projectSchedule")
public class ProjectScheduleController {

    @Resource
    private ProjectInfoService projectInfoService;

    @Resource
    private ProjectExamineService projectExamineService;


    /**
     * 项目管理 进度填报
     *
     * @param projectSchedule
     * @return ResultInfo 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @RequestMapping(value = "/SaveProReport", method = RequestMethod.POST)
    @ResponseBody
    public JsonData SaveProReport(@RequestBody ProjectSchedule projectSchedule) {
        try {
            JsonData result = projectInfoService.SaveProReport(projectSchedule);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return JsonData.success(null, 911);
        }
    }


    /**
     * 根据条件查询所有--综合查询  补报查询
     *
     * @param record
     * @return PageResult 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @PostMapping("/queryProjectList")
    @ResponseBody
    @ApiOperation(value = "根据条件查询 修改记录信息")
    public PageResult queryProjectList(@RequestBody ProjectSchedule record) {
        try {
            return projectInfoService.queryProjectList(record);
        } catch (Exception e) {
            return PageResult.success(null,null,"911",(long)0 );
        }
    }

    /**
     * 项目管理 更新进度填报
     *
     * @param projectSchedule
     * @return ResultInfo 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @RequestMapping(value = "/updateProReport", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("项目管理 更新进度填报")
    public JsonData updateProReport(@RequestBody ProjectSchedule projectSchedule) {
        try {
            JsonData result = projectInfoService.updateProReport(projectSchedule);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return JsonData.success(null, 911);
        }
    }

    /**
     * 项目管理 更新进度填报
     *
     * @param projectSchedule
     * @return ResultInfo 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @RequestMapping(value = "/updateProjectExamine", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("项目管理 季度审核")
    public JsonData  updateProjectExamine(@RequestBody ProjectSchedule projectSchedule) {
        try {
            JsonData result = projectExamineService.updateProjectExamine(projectSchedule);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return JsonData.success(null, 911);
        }
    }

    /***
     * 条件查询 项目加季度信息
     * @param searchMap 查询条件
     * @param pageNum 页数
     * @param pageSize 每页总数
     * @return pageResult 封装的返回参数
     */
    @PostMapping("/projectList/{pageNum}/{pageSize}")
    @ResponseBody
    @ApiOperation("条件查询 项目加季度信息")
    public PageResult findList(@RequestBody(required = false) SearchMap searchMap, @PathVariable("pageNum") Integer pageNum, @PathVariable("pageSize") Integer pageSize) {
        if(!StringUtils.isEmpty(searchMap.getName())){
            searchMap.setName(searchMap.getName().replaceAll("%","\\\\%")
                    .replaceAll("_","\\\\_"));
        }
        PageResult pageResult = projectExamineService.findList(searchMap, pageNum, pageSize);
        return pageResult;
    }

    @PostMapping("/saveColumns")
    @ResponseBody
    @ApiOperation("条件查询 项目加季度信息")
    public JsonData saveColumns(@RequestParam("id") String id, @RequestParam("columns") String columns, @RequestParam("values") String values) {
        try {
            JsonData pageResult = projectExamineService.saveColumns(id, columns, values);
            return pageResult;
        } catch (Exception e) {
            e.printStackTrace();
            return JsonData.success(null, 911);
        }
    }

    /**
     * 项目管理 重新提交
     *
     * @param projectSchedule
     * @return ResultInfo 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @RequestMapping(value = "/updateResubmit", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("项目管理 重新提交")
    public JsonData  updateResubmit(@RequestBody ProjectSchedule projectSchedule) {
        try {
            JsonData result = projectExamineService.updateResubmit(projectSchedule);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return JsonData.success(null, 911);
        }
    }



}
